print("IPinHand工具 V1.0")
print("[版权信息]作者QQ:3014434262")
print("[法律信息]本软件仅用于学习交流，请勿违法！否则后果自负。")
print("[初始化]正在导入库模块，请稍等...")
import requests
import json
import hashlib
import time
import os
print("[初始化]库模块导入完成!")
os.system("title IPinHand v1.0 作者qq3014434262")
print("[初始化]正在检查API可用性...")
test=["http://api.dataeverything.top/jump?jumpid=test","http://ip-api.com/json/115.191.200.34?lang=zh-CN"]
for i in test:
    print("[检查]正在请求API")
    try:
        requests.get(i)
    except:
        print("\n[错误]无法访问API!请检查网络可用性。")
        input()
        exit()
    else:
        print("[检查]成功")
print("[主程序]启动...")
Running=True
print("[日志]主循环启动")
while Running:
    print("[生成Hashcode]",end="")
    hashcode=hashlib.md5(time.ctime().encode("ansi")).hexdigest()[:10]
    print(hashcode)
    print("[状态]生成链接...")
    traplink=f"http://api.dataeverything.top/jump?jumpid={hashcode}"
    resultlink=f"http://api.dataeverything.top/seeresult?id={hashcode}"
    apilink="http://ip-api.com/json/#IP#?lang=zh-CN"
    print("[输出]请你把这个链接发给你想定位的人并让他打开:",traplink,"如果他说显示错误，那就成功了，因为这是假错误")
    input("[等待]确认他已打开后按下Enter")
    input("[等待]你确定吗？")
    input("[等待]这是最后一次提示，生成结果后Hashcode将作废！！！")
    print("[状态]请求API...")
    a=requests.get(resultlink)
    a=a.text
    if "500" in a:
        print("[错误]链接并没有被点击。按下Enter来退出。")
        input()
        exit()
    ip=a
    print("[输出]#########IP:",ip,"#################")
    print("[状态]正在等待定位API...")
    b=requests.get(apilink.replace("#IP#",ip,1))
    b=b.text
    b=json.loads(b)
    posstr=f"{b['country']}|{b['regionName']}|{b['city']}|经{b['lon']}纬{b['lat']}|ISP(运营商)信息:{b['isp']}"
    print(f"[输出]#######地址:{posstr}#########")
    if input("[输入]输入'y'(必须要小写)生成报告(更具体一些)或按下回车继续") == "y":
        report=str()
        report+=f"--------------------------------------------------\n"
        report+="IPinHand 查询报告"
        report+=f"\n请勿用于违法!"
        report+=f"\nIP:{ip}"
        report+=f"\n状态:{b['status']}"
        report+=f"\n国家:{b['country']}"
        report+=f"\n国家码:{b['countryCode']}"
        report+=f"\n地区码:{b['region']}"
        report+=f"\n城市:{b['city']}"
        report+=f"\n地区:{b['regionName']}"
        report+=f"\n经度:{b['lon']}"
        report+=f"\n纬度:{b['lat']}"
        report+=f"\n时区:{b['timezone']}"
        report+=f"\nISP(网络供应商)信息:{b['isp']}"
        report+=f"\n--------------------------------------------------"
        print(report)
    if input("[输入]输入'q'(必须要小写)退出或按下回车继续查询") == "q":
        print("[日志]退出主循环")
        Running=False

